﻿
Imports elpmis

Namespace lpmsservFunctions
    'parameters, id, int, the stringId
    'return, string, the localized string
    Public Class locstring
        Inherits internalFunction

        Public Class parameters
            Public Const id As String = "id"
        End Class

        Private Shared m As iParametersMapping = Nothing

        Shared Sub New()
            initialMapping(m, parameters.id)
        End Sub

        Public Sub New()
            MyBase.New("loc.string", m)
        End Sub

        Protected Overrides Function invoke(ByVal ctx As context, ByRef output As bare_variable) As Boolean
            Dim idv As bare_variable = Nothing
            idv = ctx.findVariable(parameters.id)
            If idv Is Nothing Then
                raiseError("expect parameter " + parameters.id, errorHandle.errorType.user)
                Return False
            ElseIf Not idv.variable().isType(typeDefination.int, True) Then
                raiseError("expect parameter " + parameters.id + " is int or var.", errorHandle.errorType.user)
                Return False
            Else
                Dim id As Int64
                Try
                    id = Convert.ToInt64(idv.value())
                Catch
                    raiseError("cannot convert parameter " + parameters.id + " to int.", errorHandle.errorType.user)
                    Return False
                End Try

                output = New bare_variable(typeDefination.string, httpServer2.currentContext().string(id))
                Return True
            End If
        End Function
    End Class
End Namespace
